java regex 10 digit number

116

java regex 10 digit number -

String regex = "^\\d{10}$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher("9876543210");
matcher.matches(); // returns true if pattern matches, else returns false

Java Regex : 4 Letters followed by 2 Integers -

public static boolean checkPass(String s){
    System.out.println(s); // Prints : Mypass85
    p = Pattern.compile("[A-Za-z]{4}[0-9]{2}");
    return p.matcher(s).find();
}

Java Regex : 4 Letters followed by 2 Integers -

public static boolean checkPass(String s){
    System.out.println(s); // Prints : Mypass85
    p = Pattern.compile("[A-Za-z]{4}[0-9]{2}");
    return p.matcher(s).find();
}

Comments

Submit
0 Comments